package com.ymatou.iapi.userservice.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.userservice.parameter.LevelBean;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.LevelCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.TestDataManager;
/**
*绑定邮箱Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_Level{
	private static LevelBean LevelBean;
	private static LevelCall LevelCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询用户等级");
	}

	@Before
	public void caseUp() {
		LevelBean=new LevelBean();
		LevelCall=new LevelCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(LevelCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Level_001() {
		Logger.start(true,"查询用户等级成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			
			LevelBean.setUserId(uid);
			LevelCall.setData(LevelBean);
			LevelCall.callService();			
			Logger.verifyEquals("true", LevelCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", LevelCall.getString("ResponseCode"), "验证ResponseCode");
			JsonObject js = LevelCall.getJsonObject().getAsJsonObject("Result");
			Logger.verifyEquals(cur.getLoginId(), js.get("LoginId").getAsString(), "验证loginId");
			Logger.verifyEquals("1", js.get("Level").getAsString(), "验证loginId");
			Logger.verifyNotNull(js.get("AcquireTime"), "acquireTime非空");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_Level_002() {
		Logger.start(false,"输入错误uid,失败");
		try {
			
			LevelBean.setUserId(-1);
			LevelCall.setData(LevelBean);
			LevelCall.callService();
			LevelCall.callService();
			Logger.verifyEquals("false", LevelCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", LevelCall.getString("ResponseCode"), "验证ResponseCode");
		//	Logger.verifyIsContains("邮箱已被使用", LevelCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Level_003() {
		Logger.start(true,"用户等级为6,查询成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			JUserCallService.ExpChange(uid, 6);
			LevelBean.setUserId(uid);
			LevelCall.setData(LevelBean);
			LevelCall.callService();			
			Logger.verifyEquals("true", LevelCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", LevelCall.getString("ResponseCode"), "验证ResponseCode");
			JsonObject js = LevelCall.getJsonObject().getAsJsonObject("Result");
			Logger.verifyEquals(cur.getLoginId(), js.get("LoginId").getAsString(), "验证loginId");
			Logger.verifyEquals("6", js.get("Level").getAsString(), "验证loginId");
			Logger.verifyNotNull(js.get("AcquireTime"), "acquireTime非空");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}